package com.example.wac.util;

import org.apache.commons.lang3.StringUtils;

/**
 * @author wuancheng
 * @description
 * @date 2022-04-20 16:10:00
 */

public class CommonUtils {
    /**
     * 保留0-2小数位 https://www.cnblogs.com/hyunbar/p/10083532.html
     */
    public static boolean saveDecimal(String str){
        if (StringUtils.isBlank(str)){
            return false;
        }
        String regex = "^(([1-9]{1}\\d*)|(0{1}))(\\.\\d{0,2})?$";
        return str.matches(regex);
    }

    /**
     * 非负整数校验
     */
    public static boolean isPositiveInteger(String str){
        if (StringUtils.isBlank(str)){
            return false;
        }
        String regex = "^[1-9]\\d*$|^0$";
        return str.matches(regex);
    }

    public static boolean isTrue(String value) {
        return value != null &&
                ("true".equalsIgnoreCase(value) ||
                        "t".equalsIgnoreCase(value) ||
                        "1".equalsIgnoreCase(value) ||
                        "enabled".equalsIgnoreCase(value) ||
                        "y".equalsIgnoreCase(value) ||
                        "yes".equalsIgnoreCase(value) ||
                        "on".equalsIgnoreCase(value));
    }
}